package artexercise;

import java.util.Scanner;

public class ExerciseSystem {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Exercise exercise = new Exercise();

        System.out.println("╔══════════════════════════════════════╗");
        System.out.println("║          算术习题生成系统            ║");
        System.out.println("╚══════════════════════════════════════╝");

        // 生成150道习题
        System.out.println("\n📝 正在生成习题...");
        exercise.generateAdditionExercises(50);
        exercise.generateSubtractionExercises(50);
        exercise.generateMixedExercises(50);

        System.out.println("\n✅ 习题生成完成！");
        System.out.println("📊 总共生成了 " + exercise.getExerciseCount() + " 道习题");

        // 显示菜单
        while (true) {
            System.out.println("\n┌─────────────────────────┐");
            System.out.println("│       请选择操作        │");
            System.out.println("├─────────────────────────┤");
            System.out.println("│  1. 显示习题(无答案)    │");
            System.out.println("│  2. 显示习题(有答案)    │");
            System.out.println("│  3. 保存习题(无答案)    │");
            System.out.println("│  4. 保存习题(有答案)    │");
            System.out.println("│  5. 退出系统           │");
            System.out.println("└─────────────────────────┘");
            System.out.print("请输入选择 (1-5): ");

            int choice;
            try {
                choice = scanner.nextInt();
            } catch (Exception e) {
                System.out.println("❌ 输入无效，请输入数字 1-5");
                scanner.nextLine(); // 清除无效输入
                continue;
            }

            switch (choice) {
                case 1:
                    exercise.displayFormatted();
                    break;
                case 2:
                    exercise.displayWithAnswers();
                    break;
                case 3:
                    exercise.saveToFile("output/exercises.txt", false);
                    break;
                case 4:
                    exercise.saveToFile("output/exercises_with_answers.txt", true);
                    break;
                case 5:
                    System.out.println("\n👋 谢谢使用！再见！");
                    scanner.close();
                    return;
                default:
                    System.out.println("❌ 无效选择，请重新输入！");
            }
        }
    }
}